package com.itheima.sfbx.insurance.handler.impl;

import com.itheima.sfbx.framework.commons.constant.insure.InsureConstant;
import com.itheima.sfbx.insurance.dto.CustomerRelationVO;
import com.itheima.sfbx.insurance.dto.DoInsureVo;
import com.itheima.sfbx.insurance.dto.WarrantyVO;
import com.itheima.sfbx.insurance.handler.InsureHandler;
import com.itheima.sfbx.insurance.service.ICustomerRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @ClassName AccidentInsureHandler.java
 * @Description 保障型意外类：保险投保、创建订单、保费计算
 */
@Service
public class AccidentInsureHandler extends SafeguardInsureHandler implements InsureHandler {
    @Autowired
    private ICustomerRelationService customerRelationService;


    @Override
    public WarrantyVO doInsure(DoInsureVo doInsureVo) {
        String id = doInsureVo.getCustomerRelationIds().get(0);
        CustomerRelationVO vo = customerRelationService.findById(id);
        if (vo != null) {
            BigDecimal income = vo.getIncome();
            if (income == null || income.compareTo(new BigDecimal(1000000)) > 0) {
                throw new RuntimeException("收入不能为空或大于100万");
            }
        }
        return super.doInsure(doInsureVo);
    }
}
